import { useBezier } from "./useBezier";


export function randomSwipe(sx: number, sy: number, ex: number, ey: number, timeMax: number = 1500) {
    const timeMin = 300;
    const leaveHeightLength = 50;

    let y2: number = sy, y3: number = ey;
    let x2: number = sx, x3: number = ex;

    if (Math.abs(ex - sx) > Math.abs(ey - sy)) {
        const my = (sy + ey) / 2
        y2 = my + random(0, leaveHeightLength)
        y3 = my - random(0, leaveHeightLength)

        let lx = (ex - sx) / 3
        x2 = sx + lx / 2 + random(0, lx)
        x3 = sx + lx + lx / 2 + random(0, lx)
    } else {
        const mx = (sx + ex) / 2
        y2 = mx + random(0, leaveHeightLength)
        y3 = mx - random(0, leaveHeightLength)

        let ly = (ey - sy) / 3
        y2 = sy + ly / 2 + random(0, ly)
        y3 = sy + ly + ly / 2 + random(0, ly)
    }

    const time = [0, random(timeMin, timeMax)]
    const track = useBezier(sx, sy, x2, y2, x3, y3, ex, ey)
    if(gestures([...time, ...track])){
        return true;
    }
    return gesture(timeMin, ...track)
}